package com.op.studyingliteapp.sender;

import android.view.MenuItem;
import android.view.View;
import com.op.studyingliteapp.R;
import io.netty.channel.ChannelHandlerContext;


public class Runtime {
    private static String TAG = "Runtime";
    //    当前接受端的ip地址
    private static String ip = null;
    //    当前接收端的通道
    private static ChannelHandlerContext context;
    //    当前发送的view
    private static View view;
    //    是否发送view的标志
    private static boolean isSend = false;
    private static MenuItem projectionButton;
    private static MenuItem deviceScanBtn;
    private static MenuItem screenShotBtn;


    public static String getIp() {
        return ip;
    }

    public static void setIp(String ip) {
        Runtime.ip = ip;
    }


    public static ChannelHandlerContext getContext() {
        return context;
    }

    public static void setContext(ChannelHandlerContext context) {
        Runtime.context = context;
    }

    public static View getView() {
        return view;
    }

    public static void setView(View view) {
        Runtime.view = view;
    }

    /**
     * 开始传屏
     */
    public static void play() {
        isSend = true;


    }

    /**
     * 暂停传屏
     */
    public static void pause() {
        isSend = false;
    }


    public static void refreshStatus() {

        if (context != null) {
            deviceScanBtn.setIcon(R.drawable.ic_router_on);
            if (projectionButton != null) {
                projectionButton.setVisible(true);
            }
            if (screenShotBtn != null) {
                screenShotBtn.setVisible(false);
            }


        } else {
            deviceScanBtn.setIcon(R.drawable.ic_router_off);
            if (projectionButton != null) {
                projectionButton.setVisible(false);
            }
            if (screenShotBtn != null) {
                screenShotBtn.setVisible(true);
            }
        }


    }

    private static void checkSendStatus() {
//        if (isSend()) {
////            sendButton.setIcon(R.drawable.ic_pause_btn);
//            sendButton.setVisible(false);
//
//        } else {
//            sendButton.setIcon(R.drawable.ic_play_btn);
//        }


    }

    public static void refreshStatus(MenuItem projectionButton, MenuItem screenShotbtn, MenuItem deviceScanBtn) {
        Runtime.projectionButton = projectionButton;
        Runtime.deviceScanBtn = deviceScanBtn;
        Runtime.screenShotBtn = screenShotbtn;

        refreshStatus();


    }

    //是否断线
    public static boolean isOffLine() {
        return context == null;

    }

    public static boolean isSend() {
        return isSend;
    }

    public static boolean closeChannel() {
        if (!Runtime.isOffLine()) {
            Runtime.getContext().close();
            Runtime.setContext(null);
            return true;
        } else {
            return false;
        }


    }
}
